package plane;

import mainwindow.Window;
import reward.Reward;

import java.awt.image.BufferedImage;

public class Hero extends FlyingObject{

    private BufferedImage[] images = new BufferedImage[]{Window.hero0,Window.hero1};
    private boolean count = true;
    private Bullet[] bullet;
    private boolean doubleFire = false;
    private int score;

    public Hero(){
        image = Window.hero0;
        imageWidth = image.getWidth();
        imageHeight = image.getHeight();
        x = Window.WIDTH / 2 - imageWidth / 2;
        y = Window.HEIGHT / 2;
        health = 3;
        score = 0;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public boolean isDoubleFire() {
        return doubleFire;
    }

    public void setDoubleFire(boolean doubleFire) {
        this.doubleFire = doubleFire;
    }

    @Override
    public void move() {
        if (count){
            image = images[0];
        }
        else {
            image = images[1];
        }
        count = !count;
    }

    public Bullet[] shoot(){
        int a = 1;
        if (doubleFire){
            a = 2;
        }
        Bullet[] bullets = new Bullet[a];
        if (bullets.length == 1){
            bullets[0] = new Bullet(this.x + imageWidth/2,this.y);
        }
        else {
            for (int i = 0; i < bullets.length; i++){
                bullets[i] = new Bullet(this.x + imageWidth * (i + 1)/3,this.y);
            }
        }
        return bullets;
    }

    public void addScore(int score){
        this.score += score;
    }

    public void getReward(int type){
        if (type == Reward.ADD_HEALTH){
            health += 1;
        }
        else if (type == Reward.DOUBLE_FIRE){
            doubleFire = true;
        }
    }
}
